class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int res = nums[0];
        int times = 1;
        for(int i = 1; i < nums.size(); ++i){
            if(0 == times){
                times = 1;
                res = nums[i];
            }
            else if(res == nums[i])
                ++times;
            else 
                --times;
        }
        return res;
    }
};